//
//  LGInspectDetailCT02Controller.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/3.
//

#import "LGInspectDetailCT02Controller.h"
#import "LGGetWebViewController.h"
#import "LGReportDetailCT02Cell.h"
#import "LGReportDetailContentCell.h"
#import "LGReportDetailFileCell.h"
#define viewHeight  (Screen_H-topBarHeight-viewPix(120))
@interface LGInspectDetailCT02Controller ()<UITableViewDataSource,UITableViewDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;


@end

@implementation LGInspectDetailCT02Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];

}

-(void)setFilePath:(NSString *)filePath{
    _filePath = filePath;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.tableView reloadData];
}


-(void)checkFileInformation:(UIButton *)sender{
    LGGetWebViewController *controller = [[LGGetWebViewController alloc]init];
    controller.navigationView.title = self.reportName;
    controller.urlStr = self.filePath;
    [self.navigationController pushViewController:controller animated:YES];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 3;
    }else{
        return self.filePath.length>0?1:0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        if(indexPath.row == 0){
            LGReportDetailCT02Cell *ctCell = [tableView dequeueReusableCellWithIdentifier:@"ctCell" forIndexPath:indexPath];
            ctCell.selectionStyle = UITableViewCellSelectionStyleNone;
            ctCell.dataDic = self.dataDic;
            return ctCell;
            
        }else{
            LGReportDetailContentCell *contentCell = [tableView dequeueReusableCellWithIdentifier:@"contentCell" forIndexPath:indexPath];
            contentCell.selectionStyle = UITableViewCellSelectionStyleNone;
            contentCell.title = (indexPath.row == 1)?@"检查所见":@"诊断意见";
            contentCell.content = (indexPath.row == 1)?self.dataDic[@"desc"]:self.dataDic[@"summary"];
            return contentCell;
        }
    }else{
        LGReportDetailFileCell *fileCell = [tableView dequeueReusableCellWithIdentifier:@"fileCell" forIndexPath:indexPath];
        fileCell.selectionStyle = UITableViewCellSelectionStyleNone;
        fileCell.title = [NSString stringWithFormat:@"%@.pdf",self.reportName];
        [fileCell.checkBtn addTarget:self action:@selector(checkFileInformation:) forControlEvents:UIControlEventTouchUpInside];
        return fileCell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return (section==0)?0.1:viewPix(50);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section == 0){
        UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.1)];
        return headView;
    }else{
        LGCornerHeaderView *headView = [[LGCornerHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(50))];
        headView.backgroundColor = [UIColor clearColor];
        headView.topMargin = viewPix(8);
        UIButton *titleBtn = [UIButton buttonWithTitle:@"报告原文件" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#1F6CC6" imageName:@""];
        titleBtn.frame = CGRectMake(viewPix(16), viewPix(20), 112, 27);
        [titleBtn setBackgroundImage:[UIImage imageNamed:@"就诊检查-蓝色"] forState:UIControlStateNormal];
        [headView addSubview:titleBtn];
        return headView;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return (section==0)?0.1:viewPix(16);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(section == 0){
        UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.1)];
        return footView;
        
    }else{
        LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(16))];
        footView.backgroundColor = [UIColor clearColor];
        footView.bottomMargin = viewPix(8);
        return footView;
    }
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGReportDetailCT02Cell class] forCellReuseIdentifier:@"ctCell"];
        [_tableView registerClass:[LGReportDetailContentCell class] forCellReuseIdentifier:@"contentCell"];
        [_tableView registerClass:[LGReportDetailFileCell class] forCellReuseIdentifier:@"fileCell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }
    return _tableView;
}



@end
